class RadrepliesController < ApplicationController
  before_action :set_radreply, only: [:show, :edit, :update, :destroy]
  before_action :set_user, only: [:index, :new, :edit, :create]

  # GET /radreplies
  # GET /radreplies.json
  def index
    @radreplies = @user.radreplies.all
  end

  # GET /radreplies/1
  # GET /radreplies/1.json
  def show
    @user_id = params[:user_id]
  end

  # GET /radreplies/new
  def new
    @radreply = @user.radreplies.new
  end

  # GET /radreplies/1/edit
  def edit
  end

  # POST /radreplies
  # POST /radreplies.json
  def create
    @radreply = @user.radreplies.new(radreply_params)
    @radreply.username = @user.username

    respond_to do |format|
      if @radreply.save
        format.html { redirect_to [@user, @radreply], notice: 'Radreply was successfully created.' }
        format.json { render action: 'show', status: :created, location: @radreply }
      else
        format.html { render action: 'new' }
        format.json { render json: @radreply.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /radreplies/1
  # PATCH/PUT /radreplies/1.json
  def update
    respond_to do |format|
      if @radreply.update(radreply_params)
        format.html { redirect_to user_radreply_path(params[:user_id], @radreply), notice: 'Radreply was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @radreply.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /radreplies/1
  # DELETE /radreplies/1.json
  def destroy
    @radreply.destroy
    respond_to do |format|
      format.html { redirect_to user_radreplies_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_radreply
      @radreply = Radreply.find(params[:id])
    end

    def set_user
      @user = User.find(params[:user_id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def radreply_params
      params.require(:radreply).permit(:attr, :op, :value)
    end
end
